#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import urllib.request as ur # 导入标准库，入门级网页爬虫库
import re # 导入正则表达式标准库

# 调用库的方法urlopen，类似于
home = 'http://www.4399.com/'
response = ur.urlopen(home)
text = response.read().decode('gbk')

rexp = re.compile(r'<img.*src="(.*\.jpg)"') # 正则表达式
# 匹配 src="/upload/n_20190624095245.jpg"
res = rexp.search(text) #re.search('src=".*.jpg"', text)
image_url = res.group(1)
# 分组/upload/n_20190624095245.jpg
# print(image_url)
ur.urlretrieve(image_url, 'fuck.jpg')

# chinese = [x for x in text if ord(x)>127]
# import collections
# c = collections.Counter(chinese)
# print(c.most_common(5))

